package com.example.htmlspringtest.web.controller;

import com.example.htmlspringtest.entity.oTestCompany;
import com.example.htmlspringtest.entity.oTestIndustrytype;
import com.example.htmlspringtest.entity.oTestMechatype;
import com.example.htmlspringtest.service.IsCompanyService;
import com.example.htmlspringtest.service.IsIndustryService;
import com.example.htmlspringtest.service.IsMechaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @belongsProject: HTML-Spring-test
 * @belongsPackage: com.example.htmlspringtest.web.controller
 * @author: dongmufengchun
 * @createTime: 2022-06-20  20:31
 * @description: TODO
 * @version: 1.01
 */
@RequestMapping
@Controller
public class EchartsController {

    @Autowired
    private IsIndustryService isIndustryService;

    @RequestMapping("Industry/data")
    @ResponseBody
    public Map IndustryData() {
        Map map = new HashMap();
        List<oTestIndustrytype> list = isIndustryService.findList();
        oTestIndustrytype[] num = new oTestIndustrytype[list.size()];
        for (int i = 0; i < list.size(); i++) {
            num[i] = list.get(i);
        }
        List<Map> list2 = new ArrayList<>();
        for (int j = 0; j < list.size(); j++) {
            Map m = new HashMap();
            m.put("companyTypeName", num[j].getInstryName());
            m.put("totalNumber", num[j].getInstryNum());
            list2.add(m);
        }
        map.put("IndustryData", list2);
        return map;
    }

    @Autowired
    private IsCompanyService isCompanyService;

    @RequestMapping("Company/data")
    @ResponseBody
    public Map CompanyData() {
        Map map = new HashMap();
        List<oTestCompany> list = isCompanyService.findList();
        oTestCompany[] num = new oTestCompany[list.size()];
        for (int i = 0; i < list.size(); i++) {
            num[i] = list.get(i);
        }
        List<Map> list2 = new ArrayList<>();
        for (int j = 0; j < list.size(); j++) {
            Map m = new HashMap();
            m.put("CoName", num[j].getCoName());
            m.put("CoMany", num[j].getCoMany());
            list2.add(m);
        }
        map.put("CompanyData", list2);
        return map;
    }

    @Autowired
    private IsMechaService isMechaService;

    @RequestMapping("Mecha/data")
    @ResponseBody
    public Map MechaData() {
        Map map = new HashMap();
        List<oTestMechatype> list = isMechaService.findList();
        oTestMechatype[] num = new oTestMechatype[list.size()];
        for (int i = 0; i < list.size(); i++) {
            num[i] = list.get(i);
        }
        List<Map> list2 = new ArrayList<>();
        for (int j = 0; j < list.size(); j++) {
            Map m = new HashMap();
            m.put("name", num[j].getMechaName());
            m.put("value", num[j].getVisitNum());
            list2.add(m);
        }
        map.put("MechaData", list2);
        return map;
    }
}

